package mine.mysolutions;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
class Person {
    private String name;
    private int age;
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public String getName() {
        return name;
    }
    public int getAge() {
        return age;
    }
}
public class Main {
    public static void main(String[] args) {
        List<Person> personList = List.of(
                new Person("Alice", 25),
                new Person("Bob", 30),
                new Person("Charlie", 25),
                new Person("David", 30)
        );
        Map<Integer, List<Person>> nameByAge = personList.stream()
                                                         .collect(Collectors.groupingBy(Person::getAge,
                                                                   Collectors.mapping(Function.identity(),
                                                                                       Collectors.toList())));
        System.out.println(nameByAge);
    }
}